Page({
  data: {
    showBottom: false,
    showRight: false,

    checked: false,

    userInfo: {
      showLoading: true,
      name: '张三',
      className: '2023级计算机与技术三班',
      studentId: '2306102314'
    },
    tempUserInfo: null ,

    studentInfo: [
      {
        id: 1,
        title: '收藏',
        src: '#',
        ico: 'label-o'
      },
      {
        id: 2,
        title: '学习提醒',
        src: '#',
        ico: 'underway-o'
      }
    ],
    preferDetails: [
      { id: 1, title: 'apple'},
      { id: 2, title: 'apple'},
      { id: 3, title: 'apple'},
      { id: 4, title: 'apple'},
      { id: 5, title: 'apple'},
    ],

    noticeInfo: [
      { id: 1, title: '关于近日即将关闭维护的通知...'},
      { id: 2, title: '系统升级详情...'},
      { id: 3, title: '部分同学账号异常维护通知...'},
      { id: 4, title: '欢迎各学院同学加入软件协会...'},
    ],

    systemInfo: [
      { id: 1, title: '设置', ico: 'setting-o'},
      { id: 2, title: '消息', ico: 'envelop-o'},
    ],


  },

  onLoad() {
    this.setData({
      tempUserInfo: {...this.data.userInfo}
    });
  },

  showPopup(e) {
    const type = e.currentTarget.dataset.type;
    if(type === 'bottom') {
      this.setData({ showBottom: true });
    } else {
      this.setData({ showRight: true });
    }
  },

  onClose(e) {
    const type = e.currentTarget.dataset.type;
    if(type === 'bottom') {
      this.setData({ showBottom: false });
    } else {
      this.setData({ showRight: false });
    }
  },

  onNameChange(event) {
    const name = event.detail;
    this.setData({
      'tempUserInfo.name': name
    });
  },

  onClassNameChange(event) {
    const className = event.detail;
    this.setData({
      'tempUserInfo.className': className
    });
  },

  onStudentIdChange(event) {
    const studentId = event.detail;
    this.setData({
      'tempUserInfo.studentId': studentId
    });
  },

  saveUserInfo() {
    this.setData({ showLoading: true });
    setTimeout(() => {
      this.setData({ showLoading: false });
      this.setData({
        userInfo: this.data.tempUserInfo,
        showBottom: false
      });
      wx.showToast({
        title: '保存成功',
        icon: 'success'
      });
      
    }, 500); 
  },

  onSwitchChange(e) {
    const isChecked = e.detail; // 获取 switch 的当前状态
    this.setData({ checked: isChecked });

    if (isChecked) {
      wx.showToast({
        title: '已开启学习提醒',
        icon: 'success',
        duration: 1000
      });
    } else {
      wx.showToast({
        title: '已关闭学习提醒',
        icon: 'fail',
        duration: 1000
      });
    }
  }


});